package com.example.controller.user;

import com.example.common.Result;
import com.example.dto.UserLoginDTO;
import com.example.entity.User;
import com.example.service.UserService;
import com.example.vo.UserLoginVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2025-03-30
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    // 注册功能
    @PostMapping("/register")
    public Result<Object> register(@RequestBody User user) {
        userService.saveUser(user);
        return Result.success();
    }

    @PostMapping("/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        UserLoginVO vo = userService.login(userLoginDTO);
        return Result.success(vo);
    }
}
